﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using RMS.Controller;

namespace RMS.View
{
    public partial class AcademicProgramView : UserControl
    {
        private AcademicProgramController _controller;

        public AcademicProgramView()
        {
            InitializeComponent();
        }

        public AcademicProgramController Controller
        {
            get { return this._controller; }
            set { this._controller = value; }
        }

        private void listViewPrograms_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listViewPrograms.SelectedItems.Count <= 0) return;
            ListViewItem item = this.listViewPrograms.SelectedItems[0];
            this.textBoxId.Text = item.SubItems[1].Text;
            this.textBoxName.Text = item.SubItems[2].Text;
            this.textBoxDescription.Text = item.SubItems[3].Text;
            this.textBoxSemesters.Text = item.SubItems[4].Text;
            this.comboBoxType.Text = item.SubItems[5].Text;
        }

        public void PopulateProgramList(List<Model.AcademicProgram> listPrograms)
        {
            this.listViewPrograms.Items.Clear();
            foreach (Model.AcademicProgram academicProgram in listPrograms)
            {
                ListViewItem item = new ListViewItem();
                item.Text = academicProgram.Name;
                item.SubItems.Add(academicProgram.Id.ToString());
                item.SubItems.Add(academicProgram.Name);
                item.SubItems.Add(academicProgram.Description);
                item.SubItems.Add(academicProgram.SemesterCount.ToString());
                item.SubItems.Add(academicProgram.Type.ToString());
                this.listViewPrograms.Items.Add(item);
            }
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            this._controller.HandleAddButtonClick();
        }

        private void buttonRemove_Click(object sender, EventArgs e)
        {
            if (this.listViewPrograms.SelectedItems.Count > 0)
            {
                this._controller.HandleRemoveButtonClick();
            }
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            this._controller.HandleUpdateButtonClick();
        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {
            this._controller.HandleSearchButtonClick();
        }

        public string TextBoxId
        {
            get { return this.textBoxId.Text; }
            set { this.textBoxId.Text = value; }
        }
        public string TextBoxName
        {
            get { return this.textBoxName.Text; }
            set { this.textBoxName.Text = value; }
        }
        public string TextBoxDescription
        {
            get { return this.textBoxDescription.Text; }
            set { this.textBoxDescription.Text = value; }
        }
        public string TextBoxSemesters
        {
            get { return this.textBoxSemesters.Text; }
            set { this.textBoxSemesters.Text = value; }
        }
        public string ComboBoxType
        {
            get { return this.comboBoxType.Text; }
            set { this.comboBoxType.Text = value; }
        }
    }
}
